<div class="form container">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'loan-form',
	'enableAjaxValidation'=>false,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<fieldset>
	<legend>Bank &amp; Product</legend>
<?php
/* no need to add bank.
$loanBanks=CHtml::listData(Loan::model()->findAll(array(
						'select'=>'bank',
						'distinct'=>true,
					)), 'bank', 'bank');
$loanBankId=CHtml::activeId($model,'bank');
$loanBankJs=<<<EOF
$('.loan-bank').click(function(){
	$('#$loanBankId').val($(this).html());
	return false;
});
EOF;

Yii::app()->clientScript->registerScript('loanBankTag',$loanBankJs);*/
?>
	<?php echo $form->hiddenField($model,'dealId');?>
	<div class="span-20 last">
		<?php echo $form->labelEx($model,'bank'); ?>
		<?php echo $form->textField($model,'bank',
					array('size'=>40,
						  'maxlength'=>255,
						  'value'=>$model->isNewRecord ? $model->deal->bank : $model->bank,
						  'readonly'=>'readonly')); 
		?>
		<?php /* echo $form->error($model,'bank'); ?>
		<?php foreach ($loanBanks as $loanBank){
			?> <a href="#" class="loan-bank"><?php echo $loanBank;?></a>
			<?php
		} */?>
	</div>
	<div class="clear"></div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'amount'); ?>
		<?php echo $form->textField($model,'amount',array('size'=>12,'maxlength'=>12)); ?>
		<?php echo $form->error($model,'amount'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'settlementDate'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		    'attribute'=>'settlementDate',
			'model'=>$model,
			'htmlOptions'=>array('size'=>12),
		    'options'=>array(
				//'altField'=>'#'.CHtml::activeId($model, "settlementDate"),	
		    ),	
		    'value'=>$model->settlementDate?$model->settlementDate : null,	   
		));
		?>
		<?php echo $form->error($model,'settlementDate'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'rate'); ?>
		<?php echo $form->textField($model,'rate',array('size'=>6,'maxlength'=>7)); ?>
		<?php echo $form->error($model,'rate'); ?>
	</div>
	

	<div class="span-3">
		<?php echo $form->labelEx($model,'honeymoonDate'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		    'attribute'=>'honeymoonDate',
			'model'=>$model,
			'htmlOptions'=>array('size'=>12),
		    'options'=>array(
				//'altField'=>'#'.CHtml::activeId($model, "honeymoonDate"),	
		    ),	
		    'value'=>$model->honeymoonDate?$model->honeymoonDate : null,  
		));
		?>
		<?php echo $form->error($model,'honeymoonDate'); ?>
	</div>
	<div class="clear"></div>

	<div class="span-8">
		<?php echo $form->labelEx($model,'productName'); ?>
		<?php echo $form->textField($model,'productName',array('size'=>40,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'productName'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'pricing'); ?>
		<?php echo $form->textField($model,'pricing',array('size'=>12,'maxlength'=>12)); ?>
		<?php echo $form->error($model,'pricing'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'dischargeDate'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		    'attribute'=>'dischargeDate',
			'model'=>$model,
			'htmlOptions'=>array('size'=>12),
		    'options'=>array(
				//'altField'=>'#'.CHtml::activeId($model, "dischargeDate"),	
		    ),	
		    'value'=>$model->dischargeDate?$model->dischargeDate : null,  
		));
		?>
		<?php echo $form->error($model,'dischargeDate'); ?>
	</div>
	<div class="clear"></div>

</fieldset>

<fieldset>
<legend>Accounts</legend>
	<div class="span-4">
		<?php echo $form->labelEx($model,'loanAccountBSB'); ?>
		<?php echo $form->textField($model,'loanAccountBSB',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'loanAccountBSB'); ?>
	</div>
	<div class="span-4">
		<?php echo $form->labelEx($model,'loanAccountNo'); ?>
		<?php echo $form->textField($model,'loanAccountNo',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'loanAccountNo'); ?>
	</div>
	<div class="clear"></div>
	<div class="span-4">
		<?php echo $form->labelEx($model,'savingAccountBSB'); ?>
		<?php echo $form->textField($model,'savingAccountBSB',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'savingAccountBSB'); ?>
	</div>
	<div class="span-4">
		<?php echo $form->labelEx($model,'savingAccountNo'); ?>
		<?php echo $form->textField($model,'savingAccountNo',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'savingAccountNo'); ?>
	</div>

</fieldset>


<fieldset>
<legend>Security Address</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'securityAddress'); ?>
		<?php //echo $form->textField($model,'securityAddress',array('size'=>60,'maxlength'=>255)); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
					'model'=>$model,
					'attribute'=>'securityAddress',
			    	'sourceUrl'=>Yii::app()->controller->createUrl('customer/ajaxAddressSearch'),
			      	'options'=>array(
			        	'minLength'=>'2',
						'select'=> 'js:function(event,ui) {
							$("#Loan_securityAddress").val(ui.item.address);
							$("#Loan_securitySuburb").val(ui.item.suburb);
							$("#Loan_securityPostcode").val(ui.item.postcode);
							$("#Loan_securityState").val(ui.item.state);
							$("#Loan_securityCountry").val(ui.item.country);
							return false;
			  			}',	
						'delay'=>500,
					),
			      	'htmlOptions'=>array(
						'size'=>60,
						'maxlength'=>255
			        ),
			        ));
		?>
		<?php echo $form->error($model,'securityAddress'); ?>
	</div>

	<div class="clear"></div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securitySuburb'); ?>
		<?php echo $form->textField($model,'securitySuburb',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securitySuburb'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityPostcode'); ?>
		<?php echo $form->textField($model,'securityPostcode',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityPostcode'); ?>
	</div>

	<div class="span-2">
		<?php echo $form->labelEx($model,'securityState'); ?>
		<?php echo $form->dropDownList($model,'securityState',DataUtil::getStates(),array('empty'=>'')); ?>
		<?php echo $form->error($model,'securityState'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityCountry'); ?>
		<?php echo $form->textField($model,'securityCountry',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityCountry'); ?>
	</div>
	<div class="clear"></div>
</fieldset>

<fieldset>
<legend>Security Address 2</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'securityAddress2'); ?>
		<?php //echo $form->textField($model,'securityAddress2',array('size'=>60,'maxlength'=>255)); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
					'model'=>$model,
					'attribute'=>'securityAddress2',
			    	'sourceUrl'=>Yii::app()->controller->createUrl('customer/ajaxAddressSearch'),
			      	'options'=>array(
			        	'minLength'=>'2',
						'select'=> 'js:function(event,ui) {
							$("#Loan_securityAddress2").val(ui.item.address);
							$("#Loan_securitySuburb2").val(ui.item.suburb);
							$("#Loan_securityPostcode2").val(ui.item.postcode);
							$("#Loan_securityState2").val(ui.item.state);
							$("#Loan_securityCountry2").val(ui.item.country);
							return false;
			  			}',	
						'delay'=>500,
					),
			      	'htmlOptions'=>array(
						'size'=>60,
						'maxlength'=>255
			        ),
			        ));
		?>
		<?php echo $form->error($model,'securityAddress2'); ?>
	</div>

	<div class="clear"></div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securitySuburb2'); ?>
		<?php echo $form->textField($model,'securitySuburb2',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securitySuburb2'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityPostcode2'); ?>
		<?php echo $form->textField($model,'securityPostcode2',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityPostcode2'); ?>
	</div>

	<div class="span-2">
		<?php echo $form->labelEx($model,'securityState2'); ?>
		<?php echo $form->dropDownList($model,'securityState2',DataUtil::getStates(),array('empty'=>'')); ?>
		<?php echo $form->error($model,'securityState2'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityCountry2'); ?>
		<?php echo $form->textField($model,'securityCountry2',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityCountry2'); ?>
	</div>
	<div class="clear"></div>
</fieldset>

<fieldset>
<legend>Security Address 3</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'securityAddress3'); ?>
		<?php // echo $form->textField($model,'securityAddress3',array('size'=>60,'maxlength'=>255)); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
					'model'=>$model,
					'attribute'=>'securityAddress3',
			    	'sourceUrl'=>Yii::app()->controller->createUrl('customer/ajaxAddressSearch'),
			      	'options'=>array(
			        	'minLength'=>'2',
						'select'=> 'js:function(event,ui) {
							$("#Loan_securityAddress3").val(ui.item.address);
							$("#Loan_securitySuburb3").val(ui.item.suburb);
							$("#Loan_securityPostcode3").val(ui.item.postcode);
							$("#Loan_securityState3").val(ui.item.state);
							$("#Loan_securityCountry3").val(ui.item.country);
							return false;
			  			}',	
						'delay'=>500,
					),
			      	'htmlOptions'=>array(
						'size'=>60,
						'maxlength'=>255
			        ),
			        ));
		?>
		<?php echo $form->error($model,'securityAddress3'); ?>
	</div>

	<div class="clear"></div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securitySuburb3'); ?>
		<?php echo $form->textField($model,'securitySuburb3',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securitySuburb3'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityPostcode3'); ?>
		<?php echo $form->textField($model,'securityPostcode3',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityPostcode3'); ?>
	</div>

	<div class="span-2">
		<?php echo $form->labelEx($model,'securityState3'); ?>
		<?php echo $form->dropDownList($model,'securityState3',DataUtil::getStates(),array('empty'=>'')); ?>
		<?php echo $form->error($model,'securityState3'); ?>
	</div>

	<div class="span-4">
		<?php echo $form->labelEx($model,'securityCountry3'); ?>
		<?php echo $form->textField($model,'securityCountry3',array('size'=>15,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'securityCountry3'); ?>
	</div>
	<div class="clear"></div>
</fieldset>

<fieldset>
<legend>Settlement Review</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'settlementReviewed'); ?>
		<?php echo $form->checkBox($model,'settlementReviewed'); ?>
		<?php echo $form->error($model,'settlementReviewed'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'settlementReviewComments'); ?>
		<?php echo $form->textArea($model,'settlementReviewComments',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'settlementReviewComments'); ?>
	</div>
</fieldset>
<fieldset>
<legend>Other</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'commissionPaid'); ?>
		<?php echo $form->checkBox($model,'commissionPaid'); ?>
		<?php echo $form->error($model,'commissionPaid'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'note'); ?>
		<?php echo $form->textArea($model,'note',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'note'); ?>
	</div>
	<?php if(GlobalConfiguration::isManageMode()){ ?>
	<div class="row">
		<?php echo $form->labelEx($model,'hidden'); ?>
		<?php echo $form->checkBox($model,'hidden'); ?>
		<?php echo $form->error($model,'hidden'); ?>
	</div>
	<?php } ?>
</fieldset>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->